﻿Imports Cls_Common
Imports VSModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml


Partial Class OtoRSS
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim p As List(Of RaoVat)
            Using Data As New VSEntities
                p = (From q In Data.RaoVats Where q.StatusId = 3 _
                                                And q.PublishedDate <= Now() And (q.eEffectiveDate >= Now() _
                                                Or q.eEffectiveDate Is Nothing) _
                                                  Order By q.PublishedDate Descending, q.Created Descending Select q).Take(10).ToList
            End Using
            Response.Clear()
            Response.ContentType = "application/rss+xml"
            Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
            objX.WriteStartDocument()
            objX.WriteStartElement("rss")
            objX.WriteAttributeString("version", "2.0")
            objX.WriteStartElement("channel")


            objX.WriteElementString("title", "Otosaithanh.com")
            objX.WriteElementString("link", "http://otosaithanh.com/")
            objX.WriteElementString("description", "Oto, mua ban oto, oto cu, oto moi , oto da qua su dung, oto nhap khau")
            For Each a In p
                objX.WriteStartElement("item")
                objX.WriteElementString("title", a.Title)
                objX.WriteElementString("author", a.CreatorId)
                objX.WriteElementString("link", MainDomain & a.QueryString & "-" & a.RaovatId.ToString & ".html")
                objX.WriteElementString("pubDate", String.Format("{0:R}", a.PublishedDate))
                objX.WriteElementString("description", a.Description)
                objX.WriteEndElement()
            Next
            objX.WriteEndElement()
            objX.WriteEndElement()
            objX.WriteEndDocument()
            objX.Flush()
            objX.Close()
            Response.End()
        End If

    End Sub


    
End Class
